package com.enterprise.support.utility;

import nl.justobjects.pushlet.core.Dispatcher;
import nl.justobjects.pushlet.core.Event;
import org.apache.struts2.json.JSONException;
import org.apache.struts2.json.JSONUtil;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 11-5-29
 * Time: 上午11:10
 * To change this template use File | Settings | File Templates.
 */
public class PushletUtility {
    public static String KEY_SUBJECT = "/system/synchro";

    public static void dispatcherEvent(String aSubject, String sessionid, String action, Enterprise input) {
        Event event = Event.createDataEvent(aSubject);
        try {
            event.setField("action", action);
            event.setField("data", JSONUtil.serialize(input));
        } catch (JSONException ex) {
            event.setField(action, "error:" + ex.getMessage());
            ex.printStackTrace();
        }
        Dispatcher.getInstance().unicast(event, sessionid);
    }

    public static void main(String[] args) throws JSONException {
        System.out.println(JSONUtil.serialize(null));
        /*Enterprise input=new Enterprise();
        input.set("member",new Enterprise(){{set("id","123");}}) ;
        System.out.println(JSONUtil.serialize(input));*/
    }
}
